from flask import Flask, Response, make_response, jsonify

from camera import Camera
app = Flask(__name__)

camera = Camera()


@app.route('/open')
def open_video():
    isOpen = camera.open_camera()
    dic = {
        'code': 1 if isOpen else 0,
    }
    return jsonify(dic)


@app.route('/video')
def get_video():
    isOpen = camera.isOpen
    if isOpen:
        content = camera.gather_camera_img()
        return Response(content, mimetype='multipart/x-mixed-replace; boundary=frame')
    return Response('open failure')


@app.route('/close')
def close_camera():
    camera.close_camera()
    return jsonify({
        'code': 1
    })

app.run()
